package com.namo.cchuser.controller;

import com.google.gson.Gson;
import com.namo.cchcommon.api.CommonResult;
import com.namo.cchuser.entity.User;
import com.namo.cchuser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author WangXin
 * @date 2021/4/19 10:26
 */
@RestController
@RequestMapping("/mini")
public class UserController {
    @Autowired
    Gson gson;
    @Autowired
    UserService userService;

    /**
     * 小程序用户登录
     * @param requestBody 用户信息体
     * @return
     */
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public CommonResult login(@RequestBody String requestBody){
        User user = gson.fromJson(requestBody, User.class);
        return CommonResult.success(userService.login(user));
    }

    /**
     * 获取用户信息
     * @param id 用户ID
     * @return
     */
    @RequestMapping(value = "/info",method = RequestMethod.GET)
    public CommonResult getUser(@RequestParam(value = "id") String id){
                return CommonResult.success(userService.getUser(id));
    }




}
